package com.sth.edu.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sth.commonutils.R;
import com.sth.commonutils.ordervo.CourseWebVoOrder;
import com.sth.edu.entity.Course;
import com.sth.edu.entity.chapter.ChapterVo;
import com.sth.edu.entity.vo.CourseFrontVo;
import com.sth.edu.entity.vo.CourseWebVo;
import com.sth.edu.service.ChapterService;
import com.sth.edu.service.CourseService;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/coursefront")
@CrossOrigin
@Api(description = "前台页面的课程")
public class CourseFrontController {
    @Autowired
    private CourseService courseService;

    @Autowired
    private ChapterService chapterService;

    //分页查询课程
    @PostMapping("getCourseFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page, @PathVariable long limit, @RequestBody(required = false) CourseFrontVo couresFrontVo) {
        Page<Course> pageTecher = new Page<>(page, limit);
        Map<String, Object> map = courseService.getCourseFrontList(pageTecher, couresFrontVo);
        // 返回所有分页数据
        return R.ok().data(map);
    }

    // 2. 课程详情查询
    @GetMapping("getCourseFrontInfo/{courseId}")
    public R getCourseFrontInfo(@PathVariable String courseId) {
        CourseWebVo courseWebVo = courseService.getBaseCourseInfo(courseId);

        List<ChapterVo> ChapterVoList = chapterService.getChapterVideoByCourseId(courseId);
        return R.ok().data("courseWebVo", courseWebVo).data("chapterVoList", ChapterVoList);
    }

    //根据课程id查询课程信息
    @GetMapping("getCourseInfoOrder/{id}")
    public CourseWebVoOrder getCourseInfoOrder(@PathVariable String id) {
        CourseWebVo baseCourseInfo = courseService.getBaseCourseInfo(id);
        CourseWebVoOrder courseWebVoOrder = new CourseWebVoOrder();
        BeanUtils.copyProperties(baseCourseInfo, courseWebVoOrder);
        return courseWebVoOrder;
    }

    //根据课程id查询课程信息
    @PostMapping("/eduservice/coursefront/test")
    String gettest(@RequestBody String id){
        System.out.println("----wowoo d woieor sdf");
        return "ddd";
    }
}
